/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Peso.java
 *
 * Created on 12/05/2011, 07:59:47 PM
 */

package proyecto;

/**
 *
 * @author home
 */
public class Peso extends javax.swing.JFrame {

    /** Creates new form Peso */
    public Peso() {
        initComponents();
        buttonGroup1.add(g1);
        buttonGroup1.add(k1);
        buttonGroup1.add(l1);
        buttonGroup1.add(t1);
        buttonGroup2.add(g2);
        buttonGroup2.add(k2);
        buttonGroup2.add(l2);
        buttonGroup2.add(t2);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jLabel5 = new javax.swing.JLabel();
        n = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        l1 = new javax.swing.JRadioButton();
        t1 = new javax.swing.JRadioButton();
        g1 = new javax.swing.JRadioButton();
        k1 = new javax.swing.JRadioButton();
        k2 = new javax.swing.JRadioButton();
        g2 = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        t2 = new javax.swing.JRadioButton();
        resu = new javax.swing.JTextField();
        l2 = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(0, 0, 255));
        jLabel5.setText("Peso:");

        jLabel4.setText("Resultado:");

        l1.setText("Lbr");

        t1.setText("Ton");

        g1.setText("Gr");

        k1.setText("Kg");

        k2.setText("Kg");

        g2.setText("Gr");

        jLabel2.setText("Ingresar:");

        t2.setText("Ton");

        l2.setText("Lbr");

        jLabel3.setText("Convertir a:");

        jButton1.setText("Ok");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jButton2.setText("Limpiar");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(n, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(t1)
                            .addComponent(l1)
                            .addComponent(k1)
                            .addComponent(g1)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(t2)
                            .addComponent(l2)
                            .addComponent(k2)
                            .addComponent(g2)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(resu, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(90, 90, 90))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(n)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(g1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(k1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(l1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(t1))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(g2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(k2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(l2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(t2)))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(resu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        // TODO add your handling code here:
        n.setText("");
        resu.setText("");
    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
    double num=Double.parseDouble(n.getText());
    double res;
    if (g1.isSelected()&&g2.isSelected()){
    resu.setText(String.valueOf(num));
    }
    if  (g1.isSelected()&&k2.isSelected()){
    res=num/1000;
    resu.setText(String.valueOf(res));
    }
    if  (g1.isSelected()&&l2.isSelected()){
    res=num/1000;
    res=res/2.2;
    resu.setText(String.valueOf(res));
    }
    if (g1.isSelected()&&t2.isSelected()){
    res=num/1000;
    res=res/907.18;
    resu.setText(String.valueOf(res));
    }
    if (k1.isSelected()&&g2.isSelected()){
    res=num*1000;
    resu.setText(String.valueOf(res));
    }
    if  (k1.isSelected()&&k2.isSelected()){
    resu.setText(String.valueOf(num));
    }
    if  (k1.isSelected()&&l2.isSelected()){
    res=num*2.2;
    resu.setText(String.valueOf(res));
    }
    if (k1.isSelected()&&t2.isSelected()){
    res=num/907.18;
    resu.setText(String.valueOf(res));
    }
    if (l1.isSelected()&&g2.isSelected()){
    res=num*453.59;
    resu.setText(String.valueOf(res));
    }
    if (l1.isSelected()&&k2.isSelected()){
    res=num/2.2;
    resu.setText(String.valueOf(res));
    }
    if (l1.isSelected()&&l2.isSelected()){
    resu.setText(String.valueOf(num));
    }
    if (l1.isSelected()&&t2.isSelected()){
    res=num/2000;
    resu.setText(String.valueOf(res));
    }
    if (t1.isSelected()&&g2.isSelected()){
    res=num*907180;
    resu.setText(String.valueOf(res));
    }
    if (t1.isSelected()&&k2.isSelected()){
    res=num*907.18 ;
    resu.setText(String.valueOf(res));
    }
    if (t1.isSelected()&&l2.isSelected()){
    res=num*2000;
    resu.setText(String.valueOf(res));
    }
    if (t1.isSelected()&&t2.isSelected()){
    resu.setText(String.valueOf(num));}
    }//GEN-LAST:event_jButton1MouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Peso().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JRadioButton g1;
    private javax.swing.JRadioButton g2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JRadioButton k1;
    private javax.swing.JRadioButton k2;
    private javax.swing.JRadioButton l1;
    private javax.swing.JRadioButton l2;
    private javax.swing.JTextField n;
    private javax.swing.JTextField resu;
    private javax.swing.JRadioButton t1;
    private javax.swing.JRadioButton t2;
    // End of variables declaration//GEN-END:variables

}
